<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 接口测试
 * @author www.dingwei.cn
 */
class Test extends CI_Controller {
//    protected $HTTP = 'http://192.168.1.35/gebi/consumer/app/';
//    protected $HTTP = 'http://139.199.211.51/gebi/consumer/app/';
    protected $HTTP = 'http://app.gebishiji.com/consumer/app/';
    protected $SESSIONID = '';

	public function __construct(){
        parent::__construct();
//        p(decode(''));
        $this->SESSIONID = encode('c8d27db161f64617d28a954ab61fcdc9240ad13f');
//        p($this->SESSIONID);
	}

    /**
     * 首页接口
     */
    public function home(){
        $url = $this->HTTP.'home/index';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 首页接口
     */
    public function index(){
        p(1);
        $url = $this->HTTP.'store/test';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 首页接口
     */
    public function cxsm(){
        $url = $this->HTTP.'home/cxsm';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'category_id' => 1
        );
        $this->_request($url, $param);
    }
	
	/**
	 * 注册验证吗
	 */
	public function forgetPasswordCode(){
        $url = 'http://192.168.1.31/bsd/adviser/app/user/getForgetPasswordVerifyCode';
        $param = array(
            'mobile' => '15736064910',
            'code' => '69827',
        );
        $this->_request($url, $param);
    }
	
	/**
	 * 登录
	 */
	public function login(){
		$url = $this->HTTP.'user/login';
		$param = array(
            'mobile' => '15736064910',
            'password' => '123456',
        );
		$this->_request($url, $param);
	}
	
	/**
	 * 忘记密码
	 */
	public function forgetPassword(){
		
		$url = 'http://192.168.1.31/bsd/adviser/app/user/forgetPassword';
		$param = array(
					'mobile' => '15086856521',
					'code' => '69827',
					'password' => 'ft01721',
					're_password' => 'ft01721',
				);
		$this->_request($url, $param);		
	}
	
	/**
	 * 密码修改
	 */
	public function password(){
	
		$url = 'http://192.168.1.31/bsd/adviser/app/user/password';
		$param = array(
				'sessionid' => encode('3d97dfe10d8650c8e9f007eaddf1ee18ad106774'),
				'old_password' => 'ft01721',
				'password' => 'ft0172',
				're_password' => 'ft0172',
		);
		$this->_request($url, $param);
	}

	/**
	 * 密码修改
	 */
	public function getInfo(){
		$url = $this->HTTP.'user/getInfo';
		$param = array(
            'sessionid' => $this->SESSIONID,
		);
		$this->_request($url, $param);
	}

    /**
     * 他的动态
     */
	public function friendsCircle(){
        $url = $this->HTTP.'friendsCircle/index';
        $param = array(
            'page' => 1,
            'type' => '2',
            'id' => '27',
            'sessionid' => $this->SESSIONID,
        );

        $this->_request($url, $param);
    }

    /**
     * 添加朋友圈
     */
    public function addFriendsCircle(){
        $url = $this->HTTP.'friendsCircle/addFriendsCircle';
        $param = array(
            'latitude' => '123',
            'longitude' => '123456',
            'address' => '重庆',
            'content' => '发布一个冬天',
            'sessionid' => $this->SESSIONID,
        );

        $this->_request($url, $param);
    }

    /**
     * 朋友圈列表
     */
    public function getFriendsCircleList(){
        $url = $this->HTTP.'friendsCircle/getFriendsCircleList';
        $param = array(
            'page' => '1',
            'type' => '2',
            'consumer_id' => '7',
        );

        $this->_request($url, $param);
    }
    /**
     * 朋友圈列表
     */
    public function myFriendsCircle(){
        $url = $this->HTTP.'friendsCircle/myFriendsCircle';
        $param = array(
            'page' => '1',
//            'type' => '2',
//            'sessionid' => $this->SESSIONID,
            'sessionid' => '0f2e2298b45d55aca73d60ccfedd100457b00f5e4116a6634816863e2489534ac4851f45c87448fd987847ad2b70930f2c482f9a45c836a0a117c7186061060286+y9GEkA5tZpBd4ZrggsSanryOKc9bSy17wy0POiuOTTcR5jnu+7ryAkNoO/Zv5CMWCARNXe68=',
        );

        $this->_request($url, $param);
    }
    /**
     * 朋友圈点赞/取消点赞
     */
    public function praise(){
        $url = $this->HTTP.'friendsCircle/praise';
        $param = array(
            'fid' => 4,
            'sessionid' => $this->SESSIONID,
        );

        $this->_request($url, $param);
    }

    /**
     * 删除我的动态
     */
    public function deleteFriendsCircle(){
        $url = $this->HTTP.'friendsCircle/deleteFriendsCircle';
        $param = array(
            'fid' => 3,
            'sessionid' => $this->SESSIONID,
        );

        $this->_request($url, $param);
    }

    /**
     * 朋友圈评论
     */
    public function addComment(){
        $url = $this->HTTP.'friendsCircle/addComment';
        $param = array(
            'fid' => 4,
            'type' => 2,
            'content' => '评论内容',
            'sessionid' => $this->SESSIONID,
        );

        $this->_request($url, $param);
    }

    /**
     * 朋友圈评论
     */
    public function friendsCircleDetail(){
        $url = $this->HTTP.'friendsCircle/friendsCircleDetail';
        $param = array(
            'fid' => 4,
            'type' => 2,
            'consumer_id' => 7,
        );

        $this->_request($url, $param);
    }

	/**
	 * 加入购物车
	 */
	public function addCart(){
		
		$url = 'http://139.199.211.51/cxsm/consumer/app/cart/add';
		$param = array(
				'sessionid' => encode('04946d8c729b22eeb3534b1d4f491bb4a7a3a2f4'),
				'product_id' => 9,
				'sort' => 1,
				'quantity' => 1,
		);
		$this->_request($url, $param);
	}
	
	/**
	 * 编辑购物车
	 */
	public function editCart(){
		
		$url = 'http://139.199.211.51/cxsm/consumer/app/cart/edit';
		$param = array(
				'sessionid' => encode('04946d8c729b22eeb3534b1d4f491bb4a7a3a2f4'),
				'product_id' => 9,
				'sort' => 3,
				'quantity' => 5,
				'change_sort' => 11
		);
		$this->_request($url, $param);
	}
	
	/**
	 * 购物车列表
	 */
	public function cartList(){
		
		$url = 'http://139.199.211.51/cxsm/consumer/app/cart/list';
		$param = array(
				'sessionid' => encode('04946d8c729b22eeb3534b1d4f491bb4a7a3a2f4'),
		);
		$this->_request($url, $param);
	}
	
	/**
	 * 删除购物车
	 */
	public function cartdelete(){
		
		$url = 'http://139.199.211.51/cxsm/consumer/app/cart/delete';
		$param = array(
				'sessionid' => encode('04946d8c729b22eeb3534b1d4f491bb4a7a3a2f4'),
				'product_id' => 9,
				'sort' => 3,
		);
		$this->_request($url, $param);
	}

    /**
     * 获取商户红包[直接到余额]
     */
    public function getMerchantBonus(){
        $url = 'http://139.199.211.51/cxsm/consumer/app/product/getMerchantBonus';
        $param = array(
            'sessionid' => encode('d9aff8813054d5e2623bf6e89a3917cd30854b6e'),
            'merchant_id' => 11,
            'bonus_id' => 22,
        );
        $this->_request($url, $param);
    }

    /**
     * 更新登录时间
     */
    public function updateLastLoginTime(){
        $url = $this->HTTP.'user/updateLastLoginTime';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 办事指南首页
     */
    public function governmentGetList(){
        $url = $this->HTTP.'Government/getList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'page' => 1,
        );
        $this->_request($url, $param);
    }

    /**
     * 余额支付
     */
    public function balance(){
        $url = $this->HTTP.'pay/balance';
        $param = array(
            'pay_code' => '20171221014114356111',
            'pay_passwd' => 123456,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 发布信息
     */
    public function saveFind(){
        $url = $this->HTTP.'find/saveFind';
        $param = array(
            'content' => '测试发布信息',
            'category_id' => 1,
            'nickname' => '小花',
            'mobile' => '15766664444',
            'address' => '重庆市江北区',
            'province' => 32,
            'city' => 394,
            'county' => 3338,
            'title' => '发发发不信息',
            'latitude' => 29.599426529395085,
            'longitude' => 106.60360367509887,
            'sessionid' => $this->SESSIONID,
            'attribute' => '[{"attr_id":"1","attr_value":"aaa"},{"attr_id":"4","attr_value":"aaa"}]'
        );
        $this->_request($url, $param);
    }

    /**
     * 分享成功赠送积分
     */
    public function giftIntegral(){
        $url = $this->HTTP.'home/giftIntegral';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取商品详情
     */
    public function getProductInfo(){
        $url = $this->HTTP.'product/getProductInfo';
        $param = array(
            'product_id' => 1,
            'merchant_id' => 4,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取商品列表
     */
    public function getProductList(){
        $url = $this->HTTP.'product/getProductList';
        $param = array(
            'custom_id' => 9,
            'merchant_id' => 5,
            'page' => 1,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取商城列表
     */
    public function getShopList(){
        $url = $this->HTTP.'home/getShopList';
        $param = array(
            'page' => 1,
            'sort' => 2,
            'latitude' => 29.599521,
            'longitude' => 106.604165,
            'limit' => 8,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取我的订单列表
     */
    public function getOrderList(){
        $url = $this->HTTP.'product/getOrderList';
        $param = array(
            'type' => 2,
            'page' => 1,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取我的订单详情
     */
    public function saveService(){
        $url = $this->HTTP.'product/saveService';
        $param = array(
            'order_id' => 104,
            'reason' => 'cesss',
            'amount' => 100,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取我的订单列表
     */
    public function getOrderDetail(){
        $url = $this->HTTP.'product/getOrderDetail';
        $param = array(
            'order_id' => 239,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取我的订单列表
     */
    public function getOrderFirst(){
        $url = $this->HTTP.'product/firstOrder';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取我的订单列表
     */
    public function getMerchantInfo(){
        $url = $this->HTTP.'product/getMerchantInfo';
        $param = array(
            'merchant_id' => 3,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 商家评论列表
     */
    public function getCommentList(){
        $url = $this->HTTP.'product/getCommentList';
        $param = array(
            'merchant_id' => 3,
            'page' => 1,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 下单
     */
    public function orderSm(){
        $url = $this->HTTP.'product/orderSm';
        $param = array(
            'param' => '[{
                "amount":8.0,"bonus_id":"0","coupon_id":"0","postal_card_id":"35","expect_arrive_time":"",
                "expect_arrive_time_s":{
                    "other":[
                        "00:45","01:05","01:25","01:45","02:05","02:25","02:45","03:05","03:25","03:45","04:05","04:25","04:45","05:05","05:25",
                        "05:45","06:05","06:25","06:45","07:05","07:25","07:45","08:05","08:25","08:45","09:05","09:25","09:45","10:05","10:25",
                        "10:45","11:05","11:25","11:45","12:05","12:25","12:45","13:05","13:25","13:45","14:05","14:25","14:45","15:05","15:25",
                        "15:45","16:05","16:25","16:45","17:05","17:25","17:45","18:05","18:25","18:45","19:05","19:25","19:45","20:05","20:25",
                        "20:45","21:05","21:25","21:45","22:05","22:25","22:45","23:05","23:25","23:45","24:05","24:25"
                    ],
                    "today":[
                        "14:58","15:18","15:38","15:58","16:18","16:38","16:58","17:18","17:38","17:58","18:18","18:38","18:58","19:18","19:38",
                        "19:58","20:18","20:38","20:58","21:18","21:38","21:58","22:18","22:38","22:58","23:18","23:38","23:58","24:18","24:38"
                    ]
                },
                "expense_type":1,"fee":4.5,"first_order_reduce":0.0,"full_cut":0.0,"lunch_box_fee":0.5,"merchant_id":"8",
                "product":[{"price":"85.00","product_id":"14","quantity":"1","sort":"0"}],
                "red":0.0,"remark":"",
                "shop_info":{
                    "address":"重庆重庆南岸区蓝光coco时代A区1栋","latitude":"29.60002","longitude":"106.6035",
                    "mobile":"15683124781","shop_name":"极品卤蛋",
                    "time":[{"business_time_end":"00:00","business_time_start":"00:00"}],
                    "week":"周一,周二,周三,周四,周五,周六,周日"
                },
                "shop_type":3,"shortage_handing":{"remark":"","value":""},
                "shortage_handing_s":[
                    {"choose":1,"label":"完全没有任何处理","value":"s1"},
                    {"choose":1,"label":"用户自己承担","value":"s2"},
                    {"choose":1,"label":"商家无条件退款","value":"s3"},
                    {"choose":1,"label":"赔偿用户货物20%金额","value":"s4"}
                ],
                "ticket":0.0
            }]',
            'address_id' => 3,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取原材料分类
     */
    public function getMaterialCategoryList(){
        $url = $this->HTTP.'material/getCategoryList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'parent_id' => 2,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取原材料分类
     */
    public function getMaterialList(){
        $url = $this->HTTP.'material/getMaterialList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'cat_id' => 6,
            'page' => 1,
            'order' => 4
        );
        $this->_request($url, $param);
    }

    /**
     * 获取原材料详情
     */
    public function getMaterialInfo(){
        $url = $this->HTTP.'material/getMaterialInfo';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'material_id' => 4,
        );
        $this->_request($url, $param);
    }

    /**
     * 获取原材料详情
     */
    public function getMaterialCommentList(){
        $url = $this->HTTP.'material/getCommentList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'page' => 1,
        );
        $this->_request($url, $param);
    }

    /**
     * 商品评论
     */
    public function saveComment(){
        $url = $this->HTTP.'product/saveComment';
        $param = array(
//            'sessionid' => $this->SESSIONID,
            'sessionid' => '0f2e2298b45d55aca73d60ccfedd100457b00f5e4116a6634816863e2489534ac4851f45c87448fd987847ad2b70930f2c482f9a45c836a0a117c7186061060286+y9GEkA5tZpBd4ZrggsSanryOKc9bSy17wy0POiuOTTcR5jnu+7ryAkNoO/Zv5CMWCARNXe68=',
            'order_id' => 264,
            'product' => '[
                    {
                        "order_product_id":"299",
                        "score":"3",
                        "content":"活动现场纠缠你发给",
                        "imgs":[
                            "http://139.199.211.51/gebi/uploads/temp/18011802230312622.jpg",
                            "http://139.199.211.51/gebi/uploads/temp/1516333428.jpg"
                        ]
                    }
                ]',
            'service_tags' => '["服务好","水果新鲜"]',
            'service_score' => 3,
            'deliveryman_tags' => '["水果新鲜","物流快"]',
            'deliveryman_score' => 3
        );
        $this->_request($url, $param);
    }

    /**
     * 获取配置原因
     */
    public function getAftersaleReason(){
        $url = $this->HTTP.'home/getCommentTags';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 售后 - 售后列表
     */
    public function getServiceList(){
        $url = $this->HTTP.'product/getServiceList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'page' => 1
        );
        $this->_request($url, $param);
    }

    /**
     * 售后 - 售后详情
     */
    public function getServiceDetail(){
        $url = $this->HTTP.'product/getServiceDetail';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'service_id' => 48
        );
        $this->_request($url, $param);
    }

    /**
     * 收藏 - 添加收藏
     */
    public function saveCollection(){
        $url = $this->HTTP.'user/saveCollection';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'relation_id' => 5,
            'type' => 3
        );
        $this->_request($url, $param);
    }

    /**
     * 收藏 - 取消收藏
     */
    public function rmCollection(){
        $url = $this->HTTP.'user/rmCollection';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'relation_id' => 5,
            'type' => 3
        );
        $this->_request($url, $param);
    }

    /**
     * 收藏 - 收藏列表
     */
    public function getCollectionList(){
        $url = $this->HTTP.'user/getCollectionList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'page' => 1,
            'type' => 2,
            'latitude' => '29.60002',
            'longitude' => '106.6035'
        );
        $this->_request($url, $param);
    }

    /**
     * 第三方登录 - 发送验证码
     */
    public function getThirdVerifyCode(){
        $url = $this->HTTP.'user/getThirdVerifyCode';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'mobile' => 15736064910,
        );
        $this->_request($url, $param);
    }

    /**
     * 第三方登录 - 绑定
     */
    public function thirdBinding(){
        $url = $this->HTTP.'user/thirdBinding';
        $param = array(
            'mobile' => 15736064910,
            'code' => 79589,
            'type' => 1,
            'value' => '66666',
            'nickname' => '哈哈哈'
        );
        $this->_request($url, $param);
    }

    /**
     * 第三方登录 - 登录
     */
    public function thirdParty(){
        $url = $this->HTTP.'user/thirdParty';
        $param = array(
            'type' => 1,
            'value' => '7777',
        );
        $this->_request($url, $param);
    }

    /**
     * 第三方登录 - 解绑
     */
    public function offBinding(){
        $url = $this->HTTP.'user/offBinding';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'type' => 1,
        );
        $this->_request($url, $param);
    }

    /**
     * 计算配送费
     */
    public function getShippingFee(){
        $url = $this->HTTP.'product/getShippingFee';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'address_id' => 8,
            'product' => '[{"product_id":"70","sort":"2","quantity":"1"}]',
        );
        $this->_request($url, $param);
    }

    /**
     * 预览订单
     */
    public function previewOrder(){
        $url = $this->HTTP.'product/previewOrder';
        $param = array(
//            'sessionid' => $this->SESSIONID,
            'product' => '[{"product_id":"25","sort":"0","quantity":"1"}]'
        );
        $this->_request($url, $param);
    }

    /**
     * 消息详情
     */
    public function messageInfo(){
        $url = $this->HTTP.'message/getInfo';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'message_id' => 463
        );
        $this->_request($url, $param);
    }

    /**
     * 便民服务 -- 评论
     */
    public function findSaveComment(){
        $url = $this->HTTP.'find/saveComment';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'find_id' => 5,
            'content' => '呵呵哈哈哈',
            'comment_id' => 14,
        );
        $this->_request($url, $param);
    }

    /**
     * 便民服务 --  列表
     */
    public function getFindList(){
        $url = $this->HTTP.'find/getFindList';
        $param = array(
            'sessionid' => $this->SESSIONID,
            'sort' => 1,
            'page' => 1,
            'category_id' => 4
        );
        $this->_request($url, $param);
    }

    /**
     * 便民服务 --  列表
     */
    public function getProductProperty(){
        $url = $this->HTTP.'product/getProductProperty';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 代金券列表
     */
    public function getCouponList(){
        $url = $this->HTTP.'user/getCouponList';
        $param = array(
            'status' => 3,
            'page' => 1,
//            'sessionid' => '',
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 代金券列表
     */
    public function getPostalCardList(){
        $url = $this->HTTP.'user/getPostalCardList';
        $param = array(
            'status' => 1,
            'page' => 1,
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

    /**
     * 代金券列表
     */
    public function getMsgStatus(){
        $url = $this->HTTP.'user/getMsgStatus';
        $param = array(
            'sessionid' => $this->SESSIONID,
        );
        $this->_request($url, $param);
    }

	/**
	 * 请求接口
	 * 
	 * @param	string	$url	请求路径
	 * @param 	array 	$param	请求参数
	 */
	private function _request($url, $param){
		
		$curl = curl_init();
	    curl_setopt($curl, CURLOPT_URL, $url);
	    curl_setopt($curl, CURLOPT_HEADER, 0);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($curl, CURLOPT_POST, true);
	    curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
	    curl_setopt($curl, CURLOPT_TIMEOUT, 30);
	    $data = curl_exec($curl);
	    if(curl_errno($curl)){
	    	p(curl_error($curl));
	    	exit(array('status' => 0, 'data' => NULL, 'message' => curl_error($curl)));
		}
	    curl_close($curl);
	    echo $data;
	}
}
